package com.gets.web.repository;

import com.gets.web.model.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by sjj on 2015/10/24 0024.
 */
@Repository // 添加注解
public interface UserRepository extends JpaRepository<UserEntity, Integer> {
    @Modifying // 说明该方法是修改操作
    @Transactional // 说明该方法是事务性操作
    // 定义查询
    // @Param注解用于提取参数
    @Query("update UserEntity us set us.password=:password where us.username=:username")
    void changePassword(@Param("username") String username, @Param("password") String password);

    @Query("select ue from UserEntity ue where ue.username=:username and ue.password=:password")
    List<UserEntity> isExist(@Param("username") String username, @Param("password") String password);

    @Query("select ue from UserEntity ue where ue.username=:username")
    List<UserEntity> userNameIsExist(@Param("username") String username);

    @Query("select ue.id from UserEntity ue where ue.username=:username")
    int getIdByUserName(@Param("username") String username);

}